import { utils } from 'hi-ui';
import { currentUserID } from "@/utils/common.js";

//采购订单数据集配置
export default {
  id: "OrderDetailEntity",
  returnTotal: true,
  modelFile: "purchase/order/dataset/OrderDetailEntity.xml",
  //主从配置
  relation: {
    selfField: ["FNUMBER"],
    parentField: ["FNUMBER"]
  },
  sortFields: [
    "FID",
    "FNUMBER",
    "FGOODSNUMBER",
    "FBARCODE",
    "FDESC",
    "FUNIT",
    "FAMOUNT",
    "FPRICE",
    "FMONEY",
    "FNOTE",
    "ORDERNO",
    "FUSERID",
    "FBRAND",
    "FRATE",
    "FRATEMONEY",
    "FENTERPRISEDESC",
    "FENTERPRISEID",
    "FSORT",
    "FSPEC",
  ],
  //字段元素
  element: {
    eleSort: {
      field: "FSORT",
    }
  },
  fields: {

    FID: {
      name: "FID", //字段ID
      label: "ID", //字段描述
      dbtype: "dbString", //数据类型
      default: {
        //默认值
        //rule: 'first', //prior   填充规则
        exps: (data) => {
          //填充表达式
          return utils.string.guid();
        },
      },
    },
    FNUMBER: {
      name: "FNUMBER", //字段ID
      label: "单号", //字段描述
      dbtype: "dbString", //数据类型
      required: true,
      readonly: true,
      length: 25,

    },
    FUSERID: {
      name: "FUSERID", //字段ID
      label: "用户", //字段描述
      dbtype: "dbString", //数据类型
      required: true,
      readonly: true,
      length: 25,
      default: {
        //默认值
        exps: (data) => {
          //填充表达式
          return currentUserID();
        },
      },
    },
    FCREATEDATE: {
      name: "FCREATEDATE", //字段ID
      label: "创建时间", //字段描述
      dbtype: "dbDate", //数据类型
      required: true,
      readonly: true,

      default: {
        //默认值
        exps: (data) => {
          //填充表达式
          return utils.date.format(new Date(), "yyyy-MM-dd HH:mm:ss");
        },
      },
    }, FGOODSNUMBER: {
      name: "FGOODSNUMBER", //字段ID
      label: "店内编码", //字段描述
      dbtype: "dbString", //数据类型
      required: true,
      length: 25,

    }, FBARCODE: {
      name: "FBARCODE", //字段ID
      label: "条形码", //字段描述
      dbtype: "dbString", //数据类型
      required: true,

      length: 25,
    },
    FDESC: {
      name: "FDESC", //字段ID
      label: "通用名称", //字段描述
      dbtype: "dbString", //数据类型
      required: true,
      // readonly: true,
      length: 25,
    },

    FSPEC: {
      name: "FSPEC", //字段ID
      label: "规格", //字段描述
      dbtype: "dbString", //数据类型
      required: true,
      readonly: true,
      length: 100,
    },

    FBRAND: {
      name: "FBRAND", //字段ID
      label: "品牌", //字段描述
      dbtype: "dbString", //数据类型
      readonly: true,
      length: 25,
    },

    FSORT: {
      name: "FSORT", //字段ID
      label: "排序", //字段描述
      dbtype: "dbInt", //数据类型
      length: 25,
    },
    FUNIT: {
      name: "FUNIT", //字段ID
      label: "单位", //字段描述
      dbtype: "dbString", //数据类型
      required: true,
      readonly: true,

      length: 25,
    }, FAMOUNT: {
      name: "FAMOUNT", //字段ID
      label: "数量", //字段描述
      dbtype: "dbFloat", //数据类型
      required: true,


      fireTarget: ["FMONEY"]
    }, FPRICE: {
      name: "FPRICE", //字段ID
      label: "采购单价", //字段描述
      dbtype: "dbFloat", //数据类型
      required: true,


      fireTarget: ["FMONEY"]
    },
    FMONEY: {
      name: "FMONEY", //字段ID
      label: "金额 ", //字段描述
      dbtype: "dbFloat", //数据类型
      required: true,
      readonly: true,
      default: {
        //默认值
        exps: (data) => {
          //填充表达式
          if (data.FPRICE && data.FAMOUNT)
            return utils.number.accMul(data.FPRICE, data.FAMOUNT)
        },
      },
      fireTarget: ["FRATEMONEY"],
    },

    FRATE: {
      name: "FRATE", //字段ID
      label: "税率", //字段描述
      dbtype: "dbFloat", //数据类型
      length: 25,
      required: true,
      fireTarget: ["FRATEMONEY"],


    },
    FRATEMONEY: {
      name: "FRATEMONEY", //字段ID
      label: "税额", //字段描述
      dbtype: "dbFloat", //数据类型
      required: true,
      readonly: true,
      length: 25,
      default: {
        //默认值
        exps: (data) => {
          //填充表达式
          if (data.FMONEY && data.FRATE)
            return utils.number.accMul(data.FMONEY, data.FRATE)
        },
      },
    },
    FENTERPRISEDESC: {
      name: "FENTERPRISEDESC", //字段ID
      label: "企业名称", //字段描述
      dbtype: "dbString", //数据类型
      length: 25,
    },
    FENTERPRISEID: {
      name: "FENTERPRISEID", //字段ID
      label: "企业ID", //字段描述
      dbtype: "dbString", //数据类型
      length: 25,
    },
    FNOTE: {
      name: "FNOTE", //字段ID
      label: "备注", //字段描述
      dbtype: "dbString", //数据类型
      length: 250,
    },
    FISRETAIL: {
      name: "FISRETAIL", //字段ID
      label: "是否拆零", //字段描述
      dbtype: "dbBoolean", //数据类型
      readonly: true,
    },

    FPROCOMPANY: {
      name: "FPROCOMPANY", //字段ID
      label: "生产厂家", //字段描述
      dbtype: "dbString", //数据类型
      length: 200,
      readonly: true,
    },
  }
}